﻿package com.addcn.texas.view.components
{	
	import flash.display.DisplayObject;	
	import flash.display.SimpleButton;		
	import flash.text.*;
	
	public class  CustomButton  extends SimpleButton	
	{			
		private var _up_color : uint = 0x333333;
		private var _over_color : uint = 0x333333;
		private var _down_color : uint = 0x333333;
		private var _size : int = 12;
		private var _txt : String;
		
		function CustomButton() : void
		{			
			super();	
			this.useHandCursor = true;		
			this.cacheAsBitmap = true;	
		}			
				
		public function initialize( r_txt : String = " ", r_size : int = 12, r_w : int = 47, r_h : int = 25 ) : void
		{
			this._txt = r_txt;
			this._size = r_size;
			var _up : CommButton_Up = new CommButton_Up;
			var _over : CommButton_Over = new CommButton_Over;
			var _down : CommButton_Down = new CommButton_Down;			
			_down.x = _down.x +1;
			_down.y = _down.y -1;
						
			this.upState = _up;
			this.overState = _over;
			this.downState = _down;
			this.hitTestState = _up;	
			
			_setTextFiled(this.upState,_up_color);
			_setTextFiled(this.overState,_over_color);
			_setTextFiled(this.downState,_down_color);
		}
		
		public function textColor(up_color: uint,over_color: uint,down_color: uint) : void
		{			
			this._up_color = up_color;
			this._over_color = over_color;
			this._down_color = down_color;
		}
		
		private function _setTextFiled(r_obj : Object,r_color:uint) : void
		{			
			var textfield:TextField = new TextField;
			var tf:TextFormat = new TextFormat;			
			tf.size = this._size;			
			tf.color = r_color;			
			textfield.text = this._txt;	
			textfield.autoSize = TextFieldAutoSize.CENTER;
			textfield.x = -textfield.width  >> 1;
			textfield.y = -textfield.height >>1 ;			
			textfield.setTextFormat(tf);
			r_obj.addChild(textfield);		
		}		
		
		public function set active(r_bool : Boolean) : void
		{
			if (r_bool) {
				var _active : CommButton_Active = new CommButton_Active;
				this.upState = _active;
				_setTextFiled(this.upState, this._up_color);
			}else {
				var _up : CommButton_Up = new CommButton_Up;
				this.upState = _active;				
			}
			_setTextFiled(this.upState, this._up_color);
		}
				
	}
	
	
}